# 测试 SmartMedicalRAG API 端点
Write-Host "=== 测试 SmartMedicalRAG API ===" -ForegroundColor Green

# 等待 API 启动
Write-Host "等待 API 启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 5

# 基础 URL
$baseUrl = "https://localhost:56798"

# 测试函数
function Test-Endpoint {
    param(
        [string]$Method,
        [string]$Url,
        [string]$Description,
        [string]$Body = $null
    )
    
    Write-Host "`n测试: $Description" -ForegroundColor Cyan
    Write-Host "URL: $Method $Url" -ForegroundColor Gray
    
    try {
        if ($Body) {
            $response = Invoke-RestMethod -Uri $Url -Method $Method -Body $Body -ContentType "application/json" -SkipCertificateCheck
        } else {
            $response = Invoke-RestMethod -Uri $Url -Method $Method -SkipCertificateCheck
        }
        
        Write-Host "✅ 成功" -ForegroundColor Green
        $response | ConvertTo-Json -Depth 3
    }
    catch {
        Write-Host "❌ 失败: $($_.Exception.Message)" -ForegroundColor Red
        if ($_.Exception.Response) {
            $statusCode = $_.Exception.Response.StatusCode
            Write-Host "状态码: $statusCode" -ForegroundColor Red
        }
    }
}

# 测试各个端点
Test-Endpoint -Method "GET" -Url "$baseUrl/" -Description "根路径重定向"
Test-Endpoint -Method "GET" -Url "$baseUrl/Home" -Description "Home 端点"
Test-Endpoint -Method "GET" -Url "$baseUrl/Home/status" -Description "Home 状态"
Test-Endpoint -Method "GET" -Url "$baseUrl/api/triage/health" -Description "Triage 健康检查"
Test-Endpoint -Method "GET" -Url "$baseUrl/api/triage/test" -Description "Triage 测试端点"

# 测试 POST 端点
$testBody = @{
    chiefComplaint = "头痛"
    symptoms = @("头痛", "恶心", "呕吐")
    medicalHistory = "无特殊病史"
    textData = "患者主诉头痛，伴有恶心呕吐症状"
} | ConvertTo-Json

Test-Endpoint -Method "POST" -Url "$baseUrl/" -Description "根路径分诊分析" -Body $testBody
Test-Endpoint -Method "POST" -Url "$baseUrl/api/triage" -Description "Triage 根路径分析" -Body $testBody
Test-Endpoint -Method "POST" -Url "$baseUrl/api/triage/analyze" -Description "Triage 详细分析" -Body $testBody

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green 